package com.sap.apitest2.deprecated.process;

import java.util.Collection;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.sap.apitest2.entity.Param;


public class ParamProcess extends EntityProcess {
	
	public Collection<Param> getParamsBySubcase(Long id)throws Exception{
		EntityManager em = this.getEntityManager();
		try{			
			Query q = em.createQuery("SELECT p FROM "+Param.class.getName()+" p WHERE P.subCaseId=?1");
			q.setParameter(1, id);
			
		    @SuppressWarnings("unchecked")
			List<Param> results = q.getResultList();			
			return results;
		}
		catch(Exception ex){
			throw ex;//this.LogException(ex);
		}
		finally{
			this.releaseEntityManager(em);
		}
	}
	
	public void saveParams(Long subcaseId, Collection<Param> entities)throws Exception{
		Collection<Param> exists = this.getParamsBySubcase(subcaseId);
		this.saveEntities(subcaseId, entities, exists);
	}
	
}
